package org.jsola.hr.query;

import io.swagger.annotations.ApiParam;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Length;
import org.jsola.core.query.BaseQuery;
import org.jsola.hr.constant.CompanySysNoticeStatus;
import org.jsola.orm.filter.Order;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;

import static org.jsola.hr.example.CompanySysNoticeExample.E_COMPANY_ID;
import static org.jsola.hr.example.CompanySysNoticeExample.E_CONTENT;
import static org.jsola.hr.example.CompanySysNoticeExample.E_CONTENT_HAS_STYLE;
import static org.jsola.hr.example.CompanySysNoticeExample.E_CREATE_USER_NAME;
import static org.jsola.hr.example.CompanySysNoticeExample.E_FINAL_EMP_IDS;
import static org.jsola.hr.example.CompanySysNoticeExample.E_FINAL_USER_IDS;
import static org.jsola.hr.example.CompanySysNoticeExample.E_IS_ONLINE;
import static org.jsola.hr.example.CompanySysNoticeExample.E_IS_TOP;
import static org.jsola.hr.example.CompanySysNoticeExample.E_OFFLINE_DATE_END;
import static org.jsola.hr.example.CompanySysNoticeExample.E_OFFLINE_DATE_START;
import static org.jsola.hr.example.CompanySysNoticeExample.E_PROPS;
import static org.jsola.hr.example.CompanySysNoticeExample.E_PUBLISH_DATE_END;
import static org.jsola.hr.example.CompanySysNoticeExample.E_PUBLISH_DATE_START;
import static org.jsola.hr.example.CompanySysNoticeExample.E_PUBLISH_EMP_RANGE;
import static org.jsola.hr.example.CompanySysNoticeExample.E_PUBLISH_EMP_RANGE_IS_ALL;
import static org.jsola.hr.example.CompanySysNoticeExample.E_PUBLISH_EMP_TYPE;
import static org.jsola.hr.example.CompanySysNoticeExample.E_PUBLISH_EMP_TYPE_IS_ALL;
import static org.jsola.hr.example.CompanySysNoticeExample.E_PUBLISH_USER_ID;
import static org.jsola.hr.example.CompanySysNoticeExample.E_PUBLISH_USER_NAME;
import static org.jsola.hr.example.CompanySysNoticeExample.E_STATUS;
import static org.jsola.hr.example.CompanySysNoticeExample.E_TITLE;
import static org.jsola.hr.example.CompanySysNoticeExample.E_TOP_DATE_CREATE_END;
import static org.jsola.hr.example.CompanySysNoticeExample.E_TOP_DATE_CREATE_START;
import static org.jsola.hr.example.CompanySysNoticeExample.N_COMPANY_ID;
import static org.jsola.hr.example.CompanySysNoticeExample.N_CONTENT;
import static org.jsola.hr.example.CompanySysNoticeExample.N_CONTENT_HAS_STYLE;
import static org.jsola.hr.example.CompanySysNoticeExample.N_CREATE_USER_NAME;
import static org.jsola.hr.example.CompanySysNoticeExample.N_FINAL_EMP_IDS;
import static org.jsola.hr.example.CompanySysNoticeExample.N_FINAL_USER_IDS;
import static org.jsola.hr.example.CompanySysNoticeExample.N_IS_ONLINE;
import static org.jsola.hr.example.CompanySysNoticeExample.N_IS_TOP;
import static org.jsola.hr.example.CompanySysNoticeExample.N_OFFLINE_DATE_END;
import static org.jsola.hr.example.CompanySysNoticeExample.N_OFFLINE_DATE_START;
import static org.jsola.hr.example.CompanySysNoticeExample.N_PROPS;
import static org.jsola.hr.example.CompanySysNoticeExample.N_PUBLISH_DATE_END;
import static org.jsola.hr.example.CompanySysNoticeExample.N_PUBLISH_DATE_START;
import static org.jsola.hr.example.CompanySysNoticeExample.N_PUBLISH_EMP_RANGE;
import static org.jsola.hr.example.CompanySysNoticeExample.N_PUBLISH_EMP_RANGE_IS_ALL;
import static org.jsola.hr.example.CompanySysNoticeExample.N_PUBLISH_EMP_TYPE;
import static org.jsola.hr.example.CompanySysNoticeExample.N_PUBLISH_EMP_TYPE_IS_ALL;
import static org.jsola.hr.example.CompanySysNoticeExample.N_PUBLISH_USER_ID;
import static org.jsola.hr.example.CompanySysNoticeExample.N_PUBLISH_USER_NAME;
import static org.jsola.hr.example.CompanySysNoticeExample.N_STATUS;
import static org.jsola.hr.example.CompanySysNoticeExample.N_TITLE;
import static org.jsola.hr.example.CompanySysNoticeExample.N_TOP_DATE_CREATE_END;
import static org.jsola.hr.example.CompanySysNoticeExample.N_TOP_DATE_CREATE_START;

/**
 * 公司系统公告信息
 *
 * @author zhr
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class CompanySysNoticeQuery extends BaseQuery {

    private static final long serialVersionUID = 1L;

    @ApiParam(value = N_COMPANY_ID, example = E_COMPANY_ID)
    @Length(max = 32)
    private String companyId;

    @ApiParam(value = N_TITLE, example = E_TITLE)
    @Length(max = 2147483647)
    private String title;

    @ApiParam(value = N_CONTENT, example = E_CONTENT)
    @Length(max = 2147483647)
    private String content;

    @ApiParam(value = N_CONTENT_HAS_STYLE, example = E_CONTENT_HAS_STYLE)
    @Length(max = 2147483647)
    private String contentHasStyle;

    @ApiParam(value = N_PUBLISH_USER_ID, example = E_PUBLISH_USER_ID)
    @Length(max = 2147483647)
    private String publishUserId;

    @ApiParam(value = N_PUBLISH_USER_NAME, example = E_PUBLISH_USER_NAME)
    @Length(max = 2147483647)
    private String publishUserName;

    /**
     * 发布时间查询范围
     */
    @ApiParam(value = N_PUBLISH_DATE_START, example = E_PUBLISH_DATE_START)
    private Date publishDateStart;
    @ApiParam(value = N_PUBLISH_DATE_END, example = E_PUBLISH_DATE_END)
    private Date publishDateEnd;


    @ApiParam(value = N_PUBLISH_EMP_RANGE_IS_ALL, example = E_PUBLISH_EMP_RANGE_IS_ALL)
    private Boolean publishEmpRangeIsAll;

    @ApiParam(value = N_PUBLISH_EMP_RANGE, example = E_PUBLISH_EMP_RANGE)
    @Length(max = 2147483647)
    private String publishEmpRange;

    @ApiParam(value = N_PUBLISH_EMP_TYPE_IS_ALL, example = E_PUBLISH_EMP_TYPE_IS_ALL)
    private Boolean publishEmpTypeIsAll;

    @ApiParam(value = N_PUBLISH_EMP_TYPE, example = E_PUBLISH_EMP_TYPE)
    @Length(max = 2147483647)
    private String publishEmpType;

    @ApiParam(value = N_FINAL_EMP_IDS, example = E_FINAL_EMP_IDS)
    @Length(max = 2147483647)
    private String finalEmpIds;

    @ApiParam(value = N_FINAL_USER_IDS, example = E_FINAL_USER_IDS)
    @Length(max = 2147483647)
    private String finalUserIds;

    /**
     * 下线时间查询范围
     */
    @ApiParam(value = N_OFFLINE_DATE_START, example = E_OFFLINE_DATE_START)
    private Date offlineDateStart;
    @ApiParam(value = N_OFFLINE_DATE_END, example = E_OFFLINE_DATE_END)
    private Date offlineDateEnd;


    @ApiParam(value = N_IS_TOP, example = E_IS_TOP)
    private Boolean isTop;

    /**
     * 发起置顶时间查询范围
     */
    @ApiParam(value = N_TOP_DATE_CREATE_START, example = E_TOP_DATE_CREATE_START)
    private Date topDateCreateStart;
    @ApiParam(value = N_TOP_DATE_CREATE_END, example = E_TOP_DATE_CREATE_END)
    private Date topDateCreateEnd;


    @ApiParam(value = N_IS_ONLINE, example = E_IS_ONLINE)
    private Boolean isOnline;

    @ApiParam(value = N_STATUS, example = E_STATUS, allowableValues = CompanySysNoticeStatus.VALUES_STR)
    private Integer status;

    @ApiParam(value = N_CREATE_USER_NAME, example = E_CREATE_USER_NAME)
    @Length(max = 50)
    private String createUserName;

    @ApiParam(value = N_PROPS, example = E_PROPS)
    @Length(max = 2147483647)
    private String props;



    @ApiParam(value = "排序字段", allowMultiple=true, type="Order" ,example = "\"orders\": [{\"property\": \"userName\",\"desc\": false}]")
    private List<Order> orders;

    /**
     * 每页的条数
     */
    @ApiParam(value = "分页参数，每页的条数", example = "20")
    @Max(value = 1000, message = "pageSize不能大于1000")
    private Integer pageSize = 20;

    /**
     * 当前第几页
     */
    @ApiParam(value = "分页参数，第几页", example = "1")
    @Min(value = 1, message = "pageNo不能小于1")
    private Integer pageNo = 1;



    /**
     * 添加排序
     * @param propertyName 属性名
     * @param desc 是否降序
     * @return this
     */
    public CompanySysNoticeQuery addOrder(String propertyName, boolean desc) {
        if (CollectionUtils.isEmpty(this.orders)) {
            this.orders = new ArrayList<>();
        }
        this.orders.add(new Order(propertyName,desc));
        return this;
    }

}

